<html>
<head><meta charset="utf-8"><title>memcmp? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html">memcmp?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244964404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244964404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244964404">(Jul 05 2021 at 18:42)</a>:</h4>
<p>It looks like slice internally uses memcmp to implement Ord and Eq for [u8]. But I can't find a public method that gives me the position of the first mismatch like memcmp does.</p>



<a name="244971332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244971332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244971332">(Jul 05 2021 at 20:24)</a>:</h4>
<p>you can do it with iterators but I don't know if that turns into a memcmp call</p>



<a name="244974123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244974123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244974123">(Jul 05 2021 at 21:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="330154">The 8472</span> <a href="#narrow/stream/219381-t-libs/topic/memcmp.3F/near/244964404">said</a>:</p>
<blockquote>
<p>It looks like slice internally uses memcmp to implement Ord and Eq for [u8]. But I can't find a public method that gives me the position of the first mismatch like memcmp does.</p>
</blockquote>
<p>memcmp doesn't do that: it just returns 1, 0, or -1 (or any positive or negative value other than 0):</p>
<p>Say we have the signature:</p>
<div class="codehilite" data-code-language="C++"><pre><span></span><code><span class="kt">int</span> <span class="nf">memcmp</span> <span class="p">(</span> <span class="k">const</span> <span class="kt">void</span> <span class="o">*</span> <span class="n">ptr1</span><span class="p">,</span> <span class="k">const</span> <span class="kt">void</span> <span class="o">*</span> <span class="n">ptr2</span><span class="p">,</span> <span class="kt">size_t</span> <span class="n">num</span> <span class="p">);</span>
</code></pre></div>
<p>If the value is &lt; 0, the first byte that differs is less in <code>ptr1</code> relative to <code>ptr2</code>. If it's 0, both are equal. If it's &gt; 0, then the first  byte that differs is greater in <code>ptr2</code> relative to <code>ptr2</code>.</p>



<a name="244974251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244974251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244974251">(Jul 05 2021 at 21:05)</a>:</h4>
<p>For example, in Apple's implementation, we have this:</p>
<div class="codehilite" data-code-language="C"><pre><span></span><code><span class="kt">int</span>
<span class="nf">memcmp</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="n">s2</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
    <span class="n">CONST</span> <span class="n">VOID</span> <span class="o">*</span><span class="n">s1</span><span class="p">;</span>         <span class="cm">/* First string. */</span>
    <span class="n">CONST</span> <span class="n">VOID</span> <span class="o">*</span><span class="n">s2</span><span class="p">;</span>         <span class="cm">/* Second string. */</span>
    <span class="kt">size_t</span>      <span class="n">n</span><span class="p">;</span>                      <span class="cm">/* Length to compare. */</span>
<span class="p">{</span>
    <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">u1</span><span class="p">,</span> <span class="n">u2</span><span class="p">;</span>

    <span class="k">for</span> <span class="p">(</span> <span class="p">;</span> <span class="n">n</span><span class="o">--</span> <span class="p">;</span> <span class="n">s1</span><span class="o">++</span><span class="p">,</span> <span class="n">s2</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">u1</span> <span class="o">=</span> <span class="o">*</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="p">)</span> <span class="n">s1</span><span class="p">;</span>
    <span class="n">u2</span> <span class="o">=</span> <span class="o">*</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="p">)</span> <span class="n">s2</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span> <span class="n">u1</span> <span class="o">!=</span> <span class="n">u2</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">u1</span><span class="o">-</span><span class="n">u2</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>So the difference is just the difference in the unsigned byte here.</p>
<p>A similarly conforming implementation can do:</p>
<div class="codehilite" data-code-language="C"><pre><span></span><code><span class="kt">int</span>
<span class="nf">memcmp</span> <span class="p">(</span><span class="k">const</span> <span class="n">PTR</span> <span class="n">str1</span><span class="p">,</span> <span class="k">const</span> <span class="n">PTR</span> <span class="n">str2</span><span class="p">,</span> <span class="kt">size_t</span> <span class="n">count</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">register</span> <span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="n">s1</span> <span class="o">=</span> <span class="p">(</span><span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span><span class="n">str1</span><span class="p">;</span>
  <span class="k">register</span> <span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="n">s2</span> <span class="o">=</span> <span class="p">(</span><span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span><span class="n">str2</span><span class="p">;</span>
  <span class="k">while</span> <span class="p">(</span><span class="n">count</span><span class="o">--</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
    <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">s1</span><span class="o">++</span> <span class="o">!=</span> <span class="o">*</span><span class="n">s2</span><span class="o">++</span><span class="p">)</span>
          <span class="k">return</span> <span class="n">s1</span><span class="p">[</span><span class="mi">-1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">s2</span><span class="p">[</span><span class="mi">-1</span><span class="p">]</span> <span class="o">?</span> <span class="mi">-1</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>
    <span class="p">}</span>
  <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>So, this is effectively just <code>cmp::Ord</code>.</p>



<a name="244974743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244974743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244974743">(Jul 05 2021 at 21:13)</a>:</h4>
<p>Probably the best way would be to do <code>iter.position</code>.</p>
<p>The code:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">index_not_equal</span><span class="p">(</span><span class="n">x</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">],</span><span class="w"> </span><span class="n">y</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">iter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">zip</span><span class="p">(</span><span class="n">y</span><span class="p">.</span><span class="n">iter</span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span><span class="p">.</span><span class="n">position</span><span class="p">(</span><span class="o">|</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">b</span><span class="p">).</span><span class="n">unwrap_or</span><span class="p">(</span><span class="kt">usize</span>::<span class="n">MAX</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Optimizes on x86_64 to:</p>
<div class="codehilite" data-code-language="GAS"><pre><span></span><code><span class="nl">example:</span><span class="err">:</span><span class="nl">index_not_equal:</span>
        <span class="nf">cmp</span>     <span class="no">rsi</span><span class="p">,</span> <span class="no">rcx</span>
        <span class="nf">cmova</span>   <span class="no">rsi</span><span class="p">,</span> <span class="no">rcx</span>
        <span class="nf">neg</span>     <span class="no">rsi</span>
        <span class="nf">mov</span>     <span class="no">rax</span><span class="p">,</span> <span class="mi">-1</span>
        <span class="nf">mov</span>     <span class="no">r9</span><span class="p">,</span> <span class="mi">-1</span>
<span class="nl">.LBB0_1:</span>
        <span class="nf">lea</span>     <span class="no">rcx</span><span class="p">,</span> <span class="p">[</span><span class="no">rsi</span> <span class="err">+</span> <span class="no">r9</span><span class="p">]</span>
        <span class="nf">cmp</span>     <span class="no">rcx</span><span class="p">,</span> <span class="mi">-1</span>
        <span class="nf">je</span>      <span class="no">.LBB0_4</span>
        <span class="nf">movzx</span>   <span class="no">ecx</span><span class="p">,</span> <span class="no">byte</span> <span class="no">ptr</span> <span class="p">[</span><span class="no">rdx</span> <span class="err">+</span> <span class="no">r9</span> <span class="err">+</span> <span class="mi">1</span><span class="p">]</span>
        <span class="nf">lea</span>     <span class="no">r8</span><span class="p">,</span> <span class="p">[</span><span class="no">r9</span> <span class="err">+</span> <span class="mi">1</span><span class="p">]</span>
        <span class="nf">cmp</span>     <span class="no">byte</span> <span class="no">ptr</span> <span class="p">[</span><span class="no">rdi</span> <span class="err">+</span> <span class="no">r9</span> <span class="err">+</span> <span class="mi">1</span><span class="p">],</span> <span class="no">cl</span>
        <span class="nf">mov</span>     <span class="no">r9</span><span class="p">,</span> <span class="no">r8</span>
        <span class="nf">je</span>      <span class="no">.LBB0_1</span>
        <span class="nf">sete</span>    <span class="no">al</span>
        <span class="nf">movzx</span>   <span class="no">eax</span><span class="p">,</span> <span class="no">al</span>
        <span class="nf">add</span>     <span class="no">rax</span><span class="p">,</span> <span class="no">r8</span>
<span class="nl">.LBB0_4:</span>
        <span class="nf">ret</span>
</code></pre></div>
<p>Which isn't half bad.</p>
<p>The memcmp implementation from Apple optimizes to:</p>
<div class="codehilite" data-code-language="GAS"><pre><span></span><code><span class="nl">memcmp:</span>
        <span class="nf">test</span>    <span class="no">rdx</span><span class="p">,</span> <span class="no">rdx</span>
        <span class="nf">je</span>      <span class="no">.L5</span>
        <span class="nf">xor</span>     <span class="no">eax</span><span class="p">,</span> <span class="no">eax</span>
        <span class="nf">jmp</span>     <span class="no">.L4</span>
<span class="nl">.L3:</span>
        <span class="nf">add</span>     <span class="no">rax</span><span class="p">,</span> <span class="mi">1</span>
        <span class="nf">cmp</span>     <span class="no">rdx</span><span class="p">,</span> <span class="no">rax</span>
        <span class="nf">je</span>      <span class="no">.L5</span>
<span class="nl">.L4:</span>
        <span class="nf">movzx</span>   <span class="no">ecx</span><span class="p">,</span> <span class="no">BYTE</span> <span class="no">PTR</span> <span class="p">[</span><span class="no">rdi</span><span class="err">+</span><span class="no">rax</span><span class="p">]</span>
        <span class="nf">movzx</span>   <span class="no">r8d</span><span class="p">,</span> <span class="no">BYTE</span> <span class="no">PTR</span> <span class="p">[</span><span class="no">rsi</span><span class="err">+</span><span class="no">rax</span><span class="p">]</span>
        <span class="nf">cmp</span>     <span class="no">cl</span><span class="p">,</span> <span class="no">r8b</span>
        <span class="nf">je</span>      <span class="no">.L3</span>
        <span class="nf">movzx</span>   <span class="no">eax</span><span class="p">,</span> <span class="no">cl</span>
        <span class="nf">sub</span>     <span class="no">eax</span><span class="p">,</span> <span class="no">r8d</span>
        <span class="nf">ret</span>
<span class="nl">.L5:</span>
        <span class="nf">xor</span>     <span class="no">eax</span><span class="p">,</span> <span class="no">eax</span>
        <span class="nf">ret</span>
</code></pre></div>
<p>So not bad, not bad at all.</p>



<a name="244975359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244975359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244975359">(Jul 05 2021 at 21:25)</a>:</h4>
<p>Ah, I thought there was some simd optimized routine to find the first mismatch. Maybe that was java that had it.</p>



<a name="244975384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244975384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244975384">(Jul 05 2021 at 21:25)</a>:</h4>
<p>You can implement I believe using SIMD operations, which will be faster for sure.</p>



<a name="244975391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244975391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244975391">(Jul 05 2021 at 21:25)</a>:</h4>
<p>But, that's going to need platform-specific instructions or features.</p>



<a name="244975462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244975462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244975462">(Jul 05 2021 at 21:27)</a>:</h4>
<p>But unless it's actually a bottleneck, just do the above code: it's probably not going to be the limiting factor in your code.</p>



<a name="244975681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244975681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244975681">(Jul 05 2021 at 21:31)</a>:</h4>
<p>On x86, you could probably implement this using _mm256_movemask_epi8 and <code>x.trailing_zeros()</code>. But you probably won't need it.</p>



<a name="244975718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244975718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244975718">(Jul 05 2021 at 21:32)</a>:</h4>
<p>I hope that helps?</p>



<a name="244975901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244975901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244975901">(Jul 05 2021 at 21:35)</a>:</h4>
<p>Yeah, I'm starting position() and see what assembly it produces in this case.</p>



<a name="244976080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244976080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244976080">(Jul 05 2021 at 21:38)</a>:</h4>
<p>Sweet. If you want to see a way to implement it in ASM for x86, this is a great starting point (memchr, not the memchr2 or the others),  since it just essentially creates a mask for n1 that's all the same byte, stored in a 256-bit mask.</p>



<a name="244976082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244976082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244976082">(Jul 05 2021 at 21:38)</a>:</h4>
<p><a href="https://github.com/BurntSushi/memchr/tree/master/src/memchr/x86">https://github.com/BurntSushi/memchr/tree/master/src/memchr/x86</a></p>



<a name="244976111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244976111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244976111">(Jul 05 2021 at 21:39)</a>:</h4>
<p>I also have a fork using packed_simd, so you can use that if you want for a more cross-platform approach:<br>
<a href="https://github.com/Alexhuszagh/rust-memchr">https://github.com/Alexhuszagh/rust-memchr</a></p>
<p>Warning: it's nightly only.</p>



<a name="244986071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244986071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244986071">(Jul 06 2021 at 01:20)</a>:</h4>
<p>Once stdsimd is in Nightly you'll be able to do this in SIMD very easily</p>



<a name="244986210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244986210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244986210">(Jul 06 2021 at 01:23)</a>:</h4>
<p>approximate pseudocode:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">slice_a</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">copied</span><span class="p">().</span><span class="n">zip</span><span class="p">(</span><span class="n">slice_b</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">copied</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">if</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="n">to_array</span><span class="p">().</span><span class="n">iter</span><span class="p">().</span><span class="n">copied</span><span class="p">().</span><span class="n">zip</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">to_array</span><span class="p">().</span><span class="n">iter</span><span class="p">().</span><span class="n">copied</span><span class="p">().</span><span class="n">position</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="o">|</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">y</span><span class="p">).</span><span class="n">unwrap</span><span class="p">();</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">lane_count</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="244986262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/memcmp%3F/near/244986262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/memcmp.3F.html#244986262">(Jul 06 2021 at 01:24)</a>:</h4>
<p>where <code>slice_a</code> and <code>slice_b</code> are slices of <code>u8xN</code> for some N you want to use, such as <code>u8x16</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>